package org.itboys.core.controller.web;

import com.alibaba.fastjson.JSONObject;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.core.entity.mysql.SundayReProductOrder;
import org.itboys.core.entity.mysql.SundayReProductOrderSKU;
import org.itboys.core.service.mysql.web.SundayReProductOrderService;
import org.itboys.core.util.ResponseMessage;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @Author：贾琦磊
 * @Date：2018/8/22
 * @Description：仓库退货单
 */
@Controller
@RequestMapping("/sunday/web/order/reProduct")
public class SundayReProductOrderController extends BaseController{
    @Autowired
    private SundayReProductOrderService reProductOrderService;
    @RequestMapping("/index")
    public String index(HttpServletRequest request){
        return "/sunday/reProductOrder/index";
    }
    @RequestMapping("/input")
    public String input(HttpServletRequest request, Model model, @RequestParam("id") Long id){
       SundayReProductOrder order = reProductOrderService.findOne(id);
        model.addAttribute("order",order);
        return "/sunday/reProductOrder/input";
    }
    @RequestMapping("/select")
    public void select(HttpServletRequest request, HttpServletResponse response){
        try {
            PageResult<SundayReProductOrder> result = reProductOrderService.select(request);
            JsonPageUtils.renderJsonPage(result.getTotal(),result.getData(),response);
        } catch (Exception e) {
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE, CommonConstants.FAIL));
        }
    }

    @RequestMapping("/setState")
    public void setState(HttpServletRequest request,HttpServletResponse response
           ,@RequestParam("id")Long id
            ,@RequestParam("state")Integer state)throws Exception{
            reProductOrderService.setState(id,state);
            ResponseMessage.success();
    }
}
